package top.wilbert.collegelink.search.service.impl;/**
 * @author augus
 * @create 2023-03-17-10:07
 */

import com.alibaba.fastjson.JSON;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.wilbert.collegelink.common.vo.es.TalkEsModel;
import top.wilbert.collegelink.search.config.CollegelinkElasticSearchConfig;
import top.wilbert.collegelink.search.constant.EsConstant;
import top.wilbert.collegelink.search.service.ElasticSaveService;

import java.io.IOException;

/**
 * @ClassName:TalkSaveServiceImpl
 * @Description:
 * @author Augus
 * @date 2023/3/17 10:07
 * @Version 1.0
 **/
@Service("elasticSaveService")
public class ElasticSaveServiceImpl implements ElasticSaveService {
    @Autowired
    RestHighLevelClient restHighLevelClient;

    @Override
    public void talkStatusOpen(TalkEsModel talkEsModel) throws IOException {
        IndexRequest indexRequest = new IndexRequest(EsConstant.TALK_INDEX);
        indexRequest.id(talkEsModel.getTalkId().toString());
        indexRequest.source(JSON.toJSONString(talkEsModel), XContentType.JSON);
        restHighLevelClient.index(indexRequest, CollegelinkElasticSearchConfig.COMMON_OPTIONS);
    }

}
